using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace CommonNetduino
{
    public class DoorContact : Sensor
    {
        private Cpu.Pin pin;
        AnalogInput analogDoorInputPort = null;
        InputPort doorInputPort = null;
        int doorInputReading = 0;

        public DoorContact(Cpu.Pin pin)
        {
            // TODO: Complete member initialization
            this.pin = pin;
            analogDoorInputPort = new AnalogInput(pin);
            analogDoorInputPort.SetRange(0, 10);
            doorInputPort = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled);

            checkIfDoorIsOpen();
        }

        public void checkIfDoorIsOpen()
        {
            //doorInputReading = analogDoorInputPort.Read();
            //if (doorInputReading <10)
            //{
            //    IsDoorOpen = true;
            //}
            //else
            //{
            //    IsDoorOpen = false;
            //}
            IsDoorOpen = doorInputPort.Read();
        }


        private bool m_IsDoorOpen;
        public bool IsDoorOpen
        {
            get
            {
                return m_IsDoorOpen;
            }
            set
            {
                m_IsDoorOpen = value;
            }
        }

    }
}
